// Copyright 2022 jeff.li. and/or its affiliates.

#include <tbir/runtime/container/user_function_private.h>

namespace tbir::runtime {

    RTView UserFunction::__getattr__(string_view var_name) const {
        MXCHECK(false) << "[UserFunction] get_attr is disabled";
        return None;
    }

    void UserFunction::__setattr__(string_view var_name, const Any &val) {
        MXCHECK(false) << "[UserFunction] set_attr is disabled";
    }

    RTValue UserFunction::generic_call(PyArgs args) {
        const auto kNumArgs = args.size() + captures_.size();
        const auto kArraySize = kNumArgs > 0 ? kNumArgs : 1;
        auto capture_size = captures_.size();
        TbirAny values[kArraySize];
        for (size_t i = 0; i < capture_size; ++i) {
            values[i] = captures_[i].value();
        }
        for (size_t i = capture_size; i < kNumArgs; ++i) {
            values[i] = args[i - capture_size].value();
        }
        TbirAny out_ret_value;
        __call__(values, kNumArgs, &out_ret_value, session_handle_2_71828182846_);
        return RTValue::MoveFromCHost(&out_ret_value);
    }

}  // namespace tbir::runtime
